﻿/// <reference path="BaseComplexListControl.js" />
/// <reference path="../Enums/Orientation.js" />

var $BaseComplexInputListControl = TA.Turbo.Controls.BaseComplexInputListControl = function BaseComplexInputListControl(clientId)
{
	if (Function.IsInherit(arguments)) return;
	
	this.BaseComplexListControl(clientId);
}
$BaseComplexInputListControl.Inherit(TA.Turbo.Controls.BaseComplexListControl);

$PropertyDefinition.Define($BaseComplexInputListControl, "RepeatDirection", "RD", Orientation.Horizontal);

var _____a;
if (_____a)
{
	$BaseComplexInputListControl.prototype = new $BaseComplexListControl();
	$BaseComplexInputListControl.prototype.BaseComplexListControl = new $BaseComplexListControl();

	$BaseComplexInputListControl.prototype._inputs = new Array();
	$BaseComplexInputListControl.prototype.get_RepeatDirection = function get_RepeatDirection() { return Orientation.Horizontal; }
}

// PUBLIC
$BaseComplexInputListControl.prototype.Init = function Init()
{
	this.BaseComplexListControl.Init.call(this);

	var inputs = this._inputs = new Array();
	var myself = this;
	this.get_Control().PerformRecursive(function(elem)
	{
		if (elem.tagName == "INPUT")
		{
			inputs.push(elem);
			elem.AddEvent("click", myself._input_Click, myself);
		}
	});
}

// INTERNAL
$BaseComplexInputListControl.prototype._ItemsGetInitValue_Fill = function _ItemsGetInitValue_Fill(collection, container)
{
	var cn = container.childNodes, cnl = cn.length;
	for (var i = 0; i < cnl; ++i)
	{
		var child = cn[i];

		if (child.tagName != "LABEL") continue;
		var item = new $ListItem();
		item.ReadAttributes(child);
		if (cn[i + 1].tagName == "DIV")
		{
			item.Text = child.innerHTML;
			++i;
			var div = cn[i];
			this._ItemsGetInitValue_Fill(item.Items, div);
		}
		else
		{
			item.Text = child.childNodes[1].nodeValue;
			item.Value = child.childNodes[0].value;
		}

		collection.push(item);
	}
}
$BaseComplexInputListControl.prototype._ClearItems = function _ClearItems()
{
	this.BaseComplexListControl._ClearItems.call(this);

	this._inputs.length = 0;
}
$BaseComplexInputListControl.prototype._CreateGroupElements = function _CreateGroupElements(item)
{
	if (_____a)
		item = new $ListItem();

	var label = document.createElement("label");
	label.innerHTML = item.Text;


	var elem;
	if (this.get_RepeatDirection() == Orientation.Horizontal)
	{
		this._GetElement("SPAN");
	}
	else
	{
		this._GetElement("DIV");
	}
	elem.className = "list_group";

	return [label, elem];
}
// HANDLERS
$BaseComplexInputListControl.prototype._input_Click = function _input_Click(e)
{
	this._OnValueChanged();
}